<?php
 
include_once "header.php";

echo "<div class='container'>
<div class='row'>";
 
require_once "../dao/blog_dao.php";
require_once "../../config/paging.php";

$modul=$_GET['modul'];
$id=$_GET['id'];
$breadcrump ="";

switch($modul){
    
    default :
	
		$p = new Paging;
        $batas = 10;
        $posisi = $p->cari_posisi($batas);
		
        echo "
            
            <table class='table table-bordered'>
                <tr><td colspan=6><a href='blog_view.php?modul=tambah'><image src='../images/add.png'><strong>     Tambah Blog</strong></a></td></tr>
                <th>ID</th><th>JUDUL</th><th>GAMBAR</th><th>CONTRIBUTOR</th><th>PUBLISH STATUS</th><th>AKSI</th>
                ";
        $blog = new Blog_Dao($class_db);
        
        $blog->get_blog(null,$posisi,$batas);
        
        //$jmldata = count($blog->blog);
        
        $data = $blog->blog;
        
        if($data!=null) {
            
           foreach($data as $blog) {            
            
            echo "
                <tr valign = top>
                    <td>$blog->blog_id</td>
                    <td><a href='blog_view.php?modul=detil&id=$blog->blog_id'>$blog->title</a></td>                                       
                    <td><image src='../../images/blog/$blog->image'width=90 heigth=30></td>
					<td>$blog->contributor</td>		
					<td>$blog->publish</td> 
                    <td><a href='blog_aksi.php?modul=publish&id=$blog->blog_id'><image src='../images/edit.gif'>Publish</a> | 
                        <a href='blog_aksi.php?modul=hapus&id=$blog->blog_id'><image src='../images/delete.gif'>Hapus</a>
					</td>
                </tr>
                ";        
            
            } 
        }else{
            echo "<tr><td colspan=5 align=center>DATA TIDAK DITEMUKAN</td></tr>";
        }
        echo "            
            </table>
            ";
			
			$blog->blog = null;
			
			$blog->get_blog();
			
			$jmldata = count($blog->blog);
        
			$jml_halaman = $p->jml_halaman($jmldata,$batas);
			//print_r($jml_halaman);
        
			$link_halaman = $p->navHalaman($modul,$_GET['halaman'],$jml_halaman);
        
			echo $link_halaman;
    break;

	case "detil":
	
		$blog = new Blog_Dao($class_db);
        
        $blog->get_blog($id);
        
		$data = $blog->blog;
		
		foreach($data as $blog) {
		
			echo "
            <table>
				<tr><td colspan=8 align='center'><h1>Detail Blog</h1></td></tr>
				<tr><td> Judul</td><td> $blog->title </td></tr>
				<tr><td> Contributor</td><td> $blog->contributor</td></tr>
				<tr><td> Content</td><td> $blog->content</td></tr>
				<tr><td colspan=2><input class='btn btn-primary' type=button value=Kembali onclick=self.history.back()></td></tr>
			</table>
            ";
		
		}
        
    break;
    
    case "tambah":
	
				
		echo "
        <form class=form method=post action=blog_aksi.php?modul=tambah enctype=multipart/form-data>
        <table class=table>
        
			
			<tr><td>Judul</td><td><input type=text name=title></td></tr>
            <tr><td>Isi</td><td><textarea cols=40 rows=10 name=content></textarea></td></tr>
            <tr><td>Gambar</td><td><input type=file name=image></td></tr>
            <tr><td></td><td><input class='btn btn-primary left' type=submit value=Simpan></td></tr>
			
			
		</table>
        </form>
        ";
		
		
        
        break;
  
        

echo "</div>";
echo "</div>";	
          
}
?>